package com.kuang.springcloud.controller;

import com.kuang.springcloud.entities.CommonResult;
import com.kuang.springcloud.entities.Payment;
import com.kuang.springcloud.service.PaymentFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class OpenFeignController {

    @Qualifier("com.kuang.springcloud.service.PaymentFeignService")
    @Autowired
    private PaymentFeignService service;


    @GetMapping("/consumer/payment/create")
    public CommonResult create(Payment payment)
    {
        return  service.create(payment);
    }
    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") long id)
    {
        return service.getPaymentById(id);
    }

    @HystrixCommand(fallbackMethod = "sayFallback",commandProperties =
    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "2000"))
    @GetMapping("/consumer/say")
    public Object say(){
        int i =10/0;
        return service.say();
    }
    public Object sayFallback(){
        return "hello 客户端降级";
    }
}
